home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS5.ZIP / DOSFIND < prev    next >
Text File  |  1986-07-22  |  7KB  |  115 lines

  1.                    Finding the Files You Want
  2.         (Personal Computing August 1986 by Miriam Liskin)
  3.  
  4.      To help you find the needles you want in the haystack of files
  5. you have accumulated, there are fundamentally two types of tools --
  6. utilities that can search any existing text files for a given string
  7. of characters, and programs that index a specified set of files in
  8. advance in preparation for rapid retieval later on.  The latter
  9. usually cost money, from a few dollars for a decent public domain
  10. program to quite a few dollars for a commercial utility.
  11.      With any computer that runs DOS 2.0 or later, you already own
  12. a program of the first type -- the FIND.EXE utility supplied with the
  13. operating system, and it's already paid for.  In its simplest
  14. invocation, this program searches an existing text file for a specified
  15. character string and displays on the screen the lines containing the
  16. search string.
  17.      FIND has three parameters that provide additional flexibility.
  18. the /V option displays all the files that do not contain a specified
  19. string.  The /C parameter causes FIND to simply count the lines that
  20. contain the desired string, without displaying each one.  These options
  21. are primarily intended for programmers.  The final option, /N, is more
  22. valuable for ordinary text search requirements.  With this parameter
  23. included in the FIND command, line numbers are included in the screen
  24. display, to show you the context of the search string.  To display all
  25. the lines with numbers, in a file called AB860815.BRF that contain the
  26. word "liability," you could use the command:
  27.  
  28. FIND /N "liability" AB860815.BRF
  29.  
  30.      Given its origin as a utility for programmers, it is not unusual
  31. that FIND is more line-oriented that most word processors.  You can,
  32. however, use it to search files created by any word processor or text
  33. editor, or in fact any files on your disk, including (although you
  34. would rarely want to do so) .COM or .EXE files.
  35.      If your word processor places a carriage return at the end of each
  36. screen line, the single lines of text displayed on the screen may not
  37. fully reveal the context of the search string.  With word processors
  38. that use a return only to mark the end of a paragraph, FIND will
  39. consider the entire paragraph to be one line.  In this case, or with
  40. word processors that do not number the lines in a file sequentially
  41. (most do not), the actual line numbers displayed by FIND may be of use
  42. only insofar as they indicate the approximate position of the search
  43. string in the file.
  44.      Used this way, FIND enables you to determine whether a given file
  45. is the one you want by telling you whether or not it contains the text
  46. you have specified.  This is only marginally better than using TYPE to
  47. display the files yourself, but there are a few tricks you can use that
  48. greatly increase the usefulness of this simple program.
  49.      You can instruct FIND to search multiple files by including more
  50. than one file name in the command line.  The program does not permit
  51. the use of the standard DOS wildcard characters (* and ?), so you must
  52. type all of the file names explicitly, separated by a single space, for
  53. example:
  54.  
  55. FIND /N "liability" AB860815.BRF AB860820.MOT AB860901.MOT AB860901.LTR
  56.  
  57.      The output of this command consists of the first file name,
  58. followed by all the lines from that file that contain the text
  59. "liability" (with line numbers), then the next file name, and so on.
  60. You can further automate the search process by creating a batch file
  61. containing one or more FIND commands, and optionally, by redirecting
  62. the output of the command to a disk file so that you do not have to
  63. sit at the computer watching the screen.  The following batch file
  64. searches six files for the text "liability" and stores the output in
  65. a file called LIABIL.TXT:
  66.  
  67. FIND /N "liability" AB860815.BRF AB860820.MOT AB860901.MOT > LIABIL.TXT
  68. FIND /N "liability" AB860901.LTR AB860910.LTR AB860912.LTR >> LIABIL.TXT
  69.  
  70.      The output file, LIABIL.TXT, is created by the first FIND command;
  71. using ">>" rather than ">" in the second and subsequent commands causes
  72. the specified output to be appended to this file instead of recreating
  73. it from scratch and thus destroying the prior contents.  Using this
  74. approach, you can carry out a lengthy search unattended and examine
  75. the resulting file at your leisure.
  76.      Note also that although the two FIND commands in this example
  77. search for the same text, this need not be the case, since they are
  78. separate and independent uses of the FIND program.  Also, because FIND
  79. differentiates between upper- and lower-case, you may want to omit the
  80. first letter of a word from the search string -- "iability" instead of
  81. "liability" -- if the word might occur at the beginning of a sentence.
  82. Using these techniques, you can construct a fairly complex search with
  83. a series of FIND commands employing different search strings.
  84.      If you have a large number of files to search, you can use another
  85. property of DOS batch files to overcome the limitation on the use of
  86. wild cards in file names supplied as input to the FIND program.  The
  87. FOR command, a DOS subcommand permitted only in batch files, permits
  88. the use of variables, written as two "%" signs followed by a letter;
  89. for example, %%F.  You can specify a set of values to be substituted
  90. in turn for the variable name, and if the variable represents a file
  91. name, you may use wild cards.  The basic form of the FOR command is:
  92.  
  93. FOR <condition> DO <command>
  94.  
  95.      To repeat the same FIND command for each file that matches the
  96. pattern AB*.*, and save the output in a file called LIABIL.TXT, you
  97. could use the following in a batch file:
  98.  
  99. FOR %%F IN (AB*.*) DO FIND /N "liability" %%F >> LIABIL.TXT
  100.  
  101.      This command searches for all of the file names that match AB*.*.
  102. Each is substituted in turn for the variable name %%f, and the
  103. resulting FIND command is carried out.  If you need to search more
  104. than one group of files, you can include lines of this form in one
  105. batch file.
  106.      FIND.EXE, which is readily available on your DOS disk and will
  107. cost you nothing, is adequate for the infrequent searches occasioned
  108. by forgetting which of a set of files contains the material you want.
  109. If you need to carry out this kind of search and retrieval more often
  110. -- for example, to gather material from previous documents for reports
  111. or research projects -- there are programs that give you far more power
  112. and flexibility.
  113.  
  114.  
  115.